package com.sita.redsun.mq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.jms.*;
import java.io.Serializable;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.springframework.test.context.ContextConfiguration;

/**
 * Created by zhebinwang on 2017/3/29.
 */
@Component("mqsender")
/*@ContextConfiguration("spring/activemq.xml")*/
public class MQSender {

    @Autowired
    @Qualifier("jmsQueueTemplate")
    private JmsTemplate jmsTemplate;
   /* @Autowired
    public MQSender(@Qualifier("jmsQueueTemplate") JmsTemplate jmsTemplate)

    {
        System.out.println("启动12");
        this.jmsTemplate=jmsTemplate;
        System.out.println("启动13");
        //@Resource(name = "jmsQueueTemplate")
         // 通过@Qualifier修饰符来注入对应的bean
    }*/

    private String queueName;

    @PostConstruct //在new 对象的时候执行
    private void init(){

        System.out.println("启动11");
    }
   /* @Autowired
    public QueueSender(@Value("${activemq.up_queue_name}") String innerupQueueName) {
        if (innerupQueueName == null) {
            queueName = System.getProperty("activemq.dspt.queue");
        } else {
            queueName = innerupQueueName;
        }
    }*/


   public void sendByString (String msgstr){



   }
    /**
     * 发送一条消息到指定的队列（目标）
     *
     * @param message   消息内容
     */
    public void send(final String message) {

        jmsTemplate.send("file.dspt", new MessageCreator() {
            @Override
            public TextMessage createMessage(Session session) throws JMSException {
                TextMessage message1= session.createTextMessage(message);
               // message1.setText(message);
                return message1;
            }
        });
    }


}
